package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Profit;
import com.ruoyi.system.service.IProfitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 成本利润分析Controller
 * 
 * @author LP
 * @date 2023-04-04
 */
@RestController
@RequestMapping("/system/profit")
public class ProfitController extends BaseController
{
    @Autowired
    private IProfitService profitService;

    /**
     * 查询成本利润分析列表
     */
    @PreAuthorize("@ss.hasPermi('system:profit:list')")
    @GetMapping("/list")
    public TableDataInfo list(Profit profit)
    {
        startPage();
        List<Profit> list = profitService.selectProfitList(profit);
        return getDataTable(list);
    }

    /**
     * 导出成本利润分析列表
     */
    @PreAuthorize("@ss.hasPermi('system:profit:export')")
    @Log(title = "成本利润分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Profit profit)
    {
        List<Profit> list = profitService.selectProfitList(profit);
        ExcelUtil<Profit> util = new ExcelUtil<Profit>(Profit.class);
        util.exportExcel(response, list, "成本利润分析数据");
    }

    /**
     * 获取成本利润分析详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:profit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(profitService.selectProfitById(id));
    }

    /**
     * 新增成本利润分析
     */
    @PreAuthorize("@ss.hasPermi('system:profit:add')")
    @Log(title = "成本利润分析", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Profit profit)
    {
        return toAjax(profitService.insertProfit(profit));
    }

    /**
     * 修改成本利润分析
     */
    @PreAuthorize("@ss.hasPermi('system:profit:edit')")
    @Log(title = "成本利润分析", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Profit profit)
    {
        return toAjax(profitService.updateProfit(profit));
    }

    /**
     * 删除成本利润分析
     */
    @PreAuthorize("@ss.hasPermi('system:profit:remove')")
    @Log(title = "成本利润分析", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(profitService.deleteProfitByIds(ids));
    }
}
